/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package madmac.setor;

import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import madmac.hibernate.util.AbstractDao;

/**
 *
 * @author atila
 */
public class SetorDao extends AbstractDao {

	private static SetorDao instance;

	private SetorDao() {
	}

	public static SetorDao getInstance() {
		if (instance == null) {
			instance = new SetorDao();
		}
		return instance;
	}

	public List findAll () {
		startOperation();
		return getSession().createCriteria(Setor.class)
				  .addOrder(Order.desc("nome")).setMaxResults(10).list();
	}

	/**
	 * Falta continuar mapeando a classe madmac.maquina.
	 * @return
	 */
	public List findAll2 () {
		startOperation();
		List lista = null;
		try {
			Criteria criteria = getSession().createCriteria(Setor.class)
					  .add(Restrictions.sqlRestriction("count (id_maquina)"));
			lista = criteria.list();
		} catch (HibernateException e) {
			handleException(e);
		}
		return lista;
	}
}
